package com.springframework;

import com.springframework.beans.factory.config.MyBeanDefinition;
import com.springframework.beans.factory.support.MyDefaultListableBeanFactory;
import com.springframework.beans.factory.support.MySimpleBeanDefinitionRegistry;
import com.springframework.beans.factory.xml.MyBeanDefinitionDocumentReader;
import com.springframework.beans.factory.xml.MyXmlBeanDefinitionReader;
import com.springframework.context.annotation.MyClassPathBeanDefinitionScanner;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.Map;
import java.util.Set;

/**
 * 应用-源码-手写
 * 理解深度的升级层次
 *
 * @author Gary
 */
public class HandwritingApplication {
    public static void main(String[] args) throws Exception {
        // 创建 BeanFactory 容器
        MySimpleBeanDefinitionRegistry beanFactory = new MySimpleBeanDefinitionRegistry();
        MyXmlBeanDefinitionReader reader = new MyXmlBeanDefinitionReader(beanFactory);
        // XML 配置文件 ClassPath 路径
        String location = "classpath:dependency-lookup-context.xml";
        // 加载配置
        int beanDefinitionsCount = reader.loadBeanDefinitions(location);
        System.out.println("Bean 定义加载的数量：" + beanDefinitionsCount);
        // 依赖查找
        System.out.println(beanFactory.getBeanDefinitionMap());

        MyClassPathBeanDefinitionScanner scanner = new MyClassPathBeanDefinitionScanner(beanFactory);
        scanner.scan("com.test.ioc.domain.annotations");
        Map<String, MyBeanDefinition> beanDefinitionMap = beanFactory.getBeanDefinitionMap();
        for (Map.Entry<String, MyBeanDefinition> entrie :beanDefinitionMap.entrySet()){
            System.out.println("key: "+entrie.getKey()+"====== v: "+entrie.getValue());
        }

        // 创建 BeanFactory 容器
//        MyDefaultListableBeanFactory beanFactory = new MyDefaultListableBeanFactory();
//        MyXmlBeanDefinitionReader reader = new MyXmlBeanDefinitionReader(beanFactory);
//        // XML 配置文件 ClassPath 路径
//        String location = "classpath:dependency-lookup-context.xml";
//        // 加载配置
//        int beanDefinitionsCount = reader.loadBeanDefinitions(location);
//        System.out.println("Bean 定义加载的数量：" + beanDefinitionsCount);
//        // 依赖查找
//        System.out.println(beanFactory.getBean("user"));;
    }

}
